<!DOCTYPE html>
<title>Service Worker: registration stress test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<body>
<script>

async_test(function(t) {
    var step = t.step_func.bind(t);
    var url = 'resources/empty-worker.js';
    var frames = [];

    var number_of_registrations = 50;
    var register_promises = [];

    for (var i = 0; i < number_of_registrations; i++) {
      var scope = base_path() + 'resources/registration-stress' + i;
      register_promises.push(with_iframe(scope)
        .then(step(function(f) {
            frames.push(f);
            return service_worker_unregister_and_register(t, url, scope);
          })));
    }

    Promise.all(register_promises)
      .then(step(function(registrations) {
          var unregister_promises = [];
          for (var i = 0; i < number_of_registrations; i++) {
            frames[i].remove();
            unregister_promises.push(registrations[i].unregister());
          }
          return Promise.all(unregister_promises);
        }))
      .then(step(function() { t.done(); }))
      .catch(unreached_rejection(t));
  }, 'Registration: stress test');

</script>
